package org.prism.thread.tick;

public class SellTick implements Runnable{
    //一共一百张票
    private int ticket = 100;

    @Override
    public void run() {
        while (true){
            synchronized (this){
                if(ticket > 0){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "卖票: 票号" + ticket);
                    ticket--;
                }else{
                    break;
                }
            }
        }
    }
}
class SellTickTest{
    public static void main(String[] args) {
        SellTick sellTick = new SellTick();
        Thread t1 = new Thread(sellTick);
        Thread t2 = new Thread(sellTick);
        Thread t3 = new Thread(sellTick);

        t1.setName("窗口一");
        t2.setName("窗口二");
        t3.setName("窗口三");

        t1.start();
        t2.start();
        t3.start();
    }


}
